<template>
  <ele-modal
    :width="750"
    :visible="visible"
    :confirm-loading="loading"
    title="提示"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    @ok="save"
  >
    <a-form
      :label-col="{ md: { span: 7 }, sm: { span: 4 }, xs: { span: 24 } }"
      :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }"
    >
      <a-row :gutter="24">
        <a-col :md="20" :sm="24" :xs="24">
          <a-form-item label=" " :colon="false">
            <span class="fs-16">接受门店回仓，接受后状态不能返回</span>
          </a-form-item>
          <a-form-item label="回仓位置" v-bind="validateInfos.to_type_code">
            <a-select
              optionFilterProp="label"
              :options="cangku"
              allow-clear
              v-model:value="form.to_type_code"
              placeholder="请选择"
              @change="cangkuChange"
              autocomplete="off"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form } from 'ant-design-vue';
  import { emailReg, phoneReg, identityReg } from 'ele-admin-pro';
  import { get_warehouse_list } from '@/api/jewelry/receipts_purchase';

  // 表格列配置
  const useForm = Form.useForm;

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
    code: String
  });

  const emit = defineEmits(['done', 'update:visible']);

  // 提交状态
  const loading = ref(false);
  const cangku = ref([]);

  // 表单数据
  const form = reactive({
    code: '',
    to_type_code: '',
    receive_status: 1,
    receive_cause: ''
  });

  onMounted(() => {
    form.code = props.code;
    get_warehouse_list({ page: 1, limit: 5000 }).then((res) => {
      cangku.value = res.list.map((item) => {
        return {
          value: String(item.code),
          label: item.name
        };
      });
    });
  });
  const cangkuChange = (value) => {
    console.log('调入仓库', value);
    form.to_type_code = value;
  };
  // 表单验证规则
  const rules = reactive({
    receive_cause: [
      {
        required: false,
        message: '请输入拒绝原因',
        trigger: 'change'
      }
    ]
  });

  const { validate, validateInfos } = useForm(form, rules);
  /* 保存编辑 */
  const save = () => {
    console.log('form', form);
    validate()
      .then(() => {
        emit('done', form);
      })
      .catch(() => {});
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
